home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AppleEvent.cp
-
- Contains: TAppleEvent is an Apple Event class that will send and receive Apple Events.
- AppleEvent.cp contains the member functions for the TAppleEvent class.
-
- Written by: Kent Sandvik
-
- Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/18/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- // INCLUDE FILES
- #ifndef _APPLEEVENT_
- #include "AppleEvent.h"
- #endif
-
- // GLOBALS
- const ProcessSerialNumber kSelf = {
- 0, kCurrentProcess};
-
-
- // _________________________________________________________________________________________________________ //
- // TAppleEvent class member function implementations
- // CONSTRUCTORS & DESTRUCTORS
- #pragma segment AppleEvent
- TAppleEvent::TAppleEvent()
- // Create a kCurrentProcess address Apple Event.
- {
- this->Initialize();
- fError = ::AECreateDesc(typeProcessSerialNumber, (Ptr) & kSelf, sizeof(ProcessSerialNumber), &fTarget);
- VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
- }
-
-
- #pragma segment AppleEvent
- TAppleEvent::TAppleEvent(OSType signature)
- // Create an AE based on the signature type.
- {
- this->Initialize();
- fSignature = signature;
-
- // Create an AEDescriptor from the signature.
- fError = ::AECreateDesc(typeApplSignature, (Ptr) & fSignature, sizeof(fSignature), &fTarget);
- VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
- }
-
-
- #pragma segment AppleEvent
- TAppleEvent::~TAppleEvent()
- {
- ::AEDisposeDesc(&fAE); // dispose our AE handle
- }
-
-
- #pragma segment AppleEvent
- void TAppleEvent::Initialize()
- // Initialize fields to known values.
- {
- fPriority = kAENormalPriority; // normal level of priority
- fTimeout = kNoTimeOut; // no waiting, just continue
- fSendMode = kAENoReply; // default we are not expecting replies
- fAE.dataHandle = NULL; // clear the message part
- }
-
-
- // MAIN INTERFACES
- #pragma segment AppleEvent
- OSErr TAppleEvent::Define(AEEventClass theClass,
- AEEventID ID)
- // Define the AE based on the AE class and ID.
- {
- fError = ::AECreateAppleEvent(theClass, ID, &fTarget, kAutoGenerateReturnID, kAnyTransactionID, &fAE);
- VASSERT(fError == noErr, ("Problems with AECreateAppleEvent = %d", fError));
-
- return fError;
- }
-
-
- #pragma segment AppleEvent
- OSErr TAppleEvent::Send()
- // Blast off the Apple Event.
- {
- fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
- VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
-
- return fError;
- }
-
-
- #pragma segment AppleEvent
- OSErr TAppleEvent::Send(AEEventClass theClass,
- AEEventID ID)
- // Blast off the AE with the specs
- {
- this->Define(theClass, ID); // define the AE
- fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
- VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
-
- return fError;
- }
-
-
- #pragma segment AppleEvent
- void TAppleEvent::SetAddress(const AEAddressDesc address)
- // Set the address of the target AE.
- {
- fError = ::AEPutAttributeDesc(&fAE, keyAddressAttr, &address);
- VASSERT(fError == noErr, ("Problems with AEPutAttributeDesc = %d", fError));
- }
-
-
- // GET/SET MEMBER FUNCTIONS
- #pragma segment AppleEvent
- long TAppleEvent::GetTimeoutValue() const
- // Get current timeout value.
- {
- return fTimeout;
- }
-
-
- #pragma segment AppleEvent
- void TAppleEvent::SetTimeoutValue(const long value)
- // Set new timeout value.
- {
- fTimeout = value;
- }
-
-
- #pragma segment AppleEvent
- AESendMode TAppleEvent::GetSendingMode() const
- // Get AE sending mode.
- {
- return fSendMode;
- }
-
-
- #pragma segment AppleEvent
- void TAppleEvent::SetSendingMode(const AESendMode mode)
- // Set new AE sending mode.
- {
- fSendMode = mode;
- }
-
-
- #pragma segment AppleEvent
- AESendPriority TAppleEvent::GetPriority() const
- // Get current priority level.
- {
- return fPriority;
- }
-
-
- #pragma segment AppleEvent
- void TAppleEvent::SetPriority(const AESendPriority value)
- // Set new priority level.
- {
- fPriority = value;
- }
-
-
- // _________________________________________________________________________________________________________ //
-
- /* Change History (most recent last):
- No Init. Date Comment
- 1 khs 11/22/92 New file
- 2 khs 1/7/93 Cleanup
- */
-
-